# -*- coding: utf-8 -*-
# @Time : 2023/3/31
# @Author : 限量老
#encoding=gbk
import os
import datetime
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
#
# today = datetime.datetime.today()
# year = today.year
# month = today.month
# date=datetime.datetime.now().strftime('%Y.%m')


def re_fileName(path,mode,date,table):
    fileList = os.listdir(path)
    num = 1
    for file in fileList:
        # print(file)

        used_fileName, extension = os.path.splitext(file)
        if extension==".xls":
            new_file = used_fileName+f"_{mode}_"+date+f"{table}" + extension
            # print(new_file)
            os.rename(path+"\\"+file, path+"\\"+new_file)
            # os.remove(file)
            print("文件%s重命名成功，新的文件名为：%s" % (path + file, path + new_file))
            num += 1


if __name__ == '__main__':
    #     path="C:/Users/Administrator/Desktop/old/"        # 目标路径
    #     path = "C:\\Users\\Administrator\\Desktop\\old\\" # 目标路径
    # path = os.getcwd()  # 获取当前目录
    path = input('请输入要改名的文件路径:')
    mode=input("请输入类型:(棉,锦):")
    date = input("请输入年月份如:(23.3):")
    table=input("请输入表名:(对帐单,明细表):")
    re_fileName(path,mode,date,table)

